Constants in a Common Assembly

Comments 0

Share to social media

We were having a discussion about constants and an interesting issue came up.  I’ve always known that when you use a constant it gets interpreted as a literal when your code compiles, but I never made the connection that this is true of referenced constants as well.  This creates a bit of an issue when you have a common assembly with constants – if you update the constants in your common assembly and then deploy just the common assembly, the assemblies that reference that common assembly will not get the “updated” constant values because it was, in essence, converted into a literal and compiled directly into the assembly.  As such, it may make more sense to use static read-only variables instead of constants if they are referenced from a common assembly.

Of course, if you deploy everything all together you won’t encounter this issue because all the assemblies will be compiled with the new constants. 

Load comments

About the author

Damon Armstrong

See Profile

Damon Armstrong is a consultant with SystemwarePS in Dallas, Texas. He is also a blogger and author of Pro ASP.NET 2.0 Website Programming and SharePoint 2013 Essentials for Developers. He specializes in the Microsoft stack with a focus on web technologies like MVC, ASP.NET, JavaScript, and SharePoint. When not staying up all night coding, he can be found watching a bunch of kids, studying Biblical topics, playing golf, or recovering from staying up all night coding.